{{ define "main" }}
  <div id="content">
    <div id="sidewrap">
      <div id="sidenav">
        {{ partial "sidenav.html" (dict "sidenavType" .Params.sidenav "data" .Site.Data "language" $.Site.Language.Lang ) }}
      </div>
      <div id="feedlinks">
        <ul>
          <li>
            <a href="{{ absLangURL ($.Site.BaseURL) }}news/feed.xml" title="FreeBSD RSS 2.0 Feed">RSS 2.0 Feed</a>
          </li>
        </ul>
      </div>
    </div>
    <div id="contentwrap">
      <h1>{{ .Title }}</h1>
      {{- .Content -}}

      {{ if .Params.loadNews }}

        {{ $newsPath := (printf "data/%s/news/news.toml" $.Language.Lang) }}

        {{ $newsData := "" }}
        {{ if (fileExists $newsPath) -}}
          {{ $data := index .Site.Data $.Language.Lang }}
          {{ $newsData = $data.news }}
        {{ else }}
          {{ $dataDefaultLanguage := index .Site.Data .Sites.First.Language.Lang }}
          {{ $newsData = $dataDefaultLanguage.news }}
        {{ end }}

        <!-- First load all year-month to the array -->
        {{ $yearsMonths := slice }}
        {{ with $newsData.news }}
          {{ range (sort .news "date" "desc") }}
            {{ $yearsMonths = $yearsMonths | append (dateFormat "2006-1" .date) }}
          {{ end }}
        {{ end }}

        <!-- Remove duplicates -->
        {{ $yearsMonths = $yearsMonths | uniq }}

        {{ $newsDayCounter := 1 }}
        {{ $newsDayPrev := false }}
        {{ range $year := seq now.Year 2010 }}
          {{ range $month := seq 12 1 }}
            {{ $yearMonth := (printf "%d-%d" $year $month) }}
            {{ if in $yearsMonths $yearMonth }}
              <h2>{{ i18n $month }} {{ $year }}</h2>
              <ul>
                {{ with $newsData.news }}
                  {{ range (sort .news "date" "desc") }}
                    {{ if eq (dateFormat "2006-1" .date) $yearMonth }}
                      {{ $newsDayCur := dateFormat "2006-01-02" .date }}
                      {{ if eq $newsDayCur $newsDayPrev }}
                        {{ $newsDayCounter = add $newsDayCounter 1 }}
                      {{ else }}
                        {{ $newsDayCounter = 1 }}
                      {{ end }}
                      <li>
                        <p class="localized">
                          <a id="{{ dateFormat "2006-01-02" .date }}:{{ $newsDayCounter }}"></a>
                          <strong>{{ dateFormat "2" .date }} {{ i18n (dateFormat "1" .date) }}:</strong>
                          {{ .description | safeHTML }}
                        </p>
                      </li>
                      {{ $newsDayPrev = $newsDayCur }}
                    {{ end }}
                  {{ end }}
                {{ end }}
              </ul>
            {{ end }}
          {{ end }}
        {{ end }}
      {{ end }}
      {{ if .GitInfo }}
      <hr />
      <div class="last-modified">
        <p><strong>{{ i18n "last-modified" }}</strong>: {{ .GitInfo.AuthorDate | time.Format ":date_long" }} {{ i18n "by" }} <a href="https://cgit.freebsd.org/doc/commit/?id={{ .GitInfo.AbbreviatedHash }}" target="_blank">{{ .GitInfo.AuthorName }}</a></p>
      </div>
      {{ end }}
    </div>
  </div>
{{ end }}
